# -*- encoding:utf-8 -*-
# !/usr/bin/env python
'''
    python-0819-05.py
    ======================
    @descript: 复制文件
    @copyright:nnz
    @author:dln
    @date: 2021/8/19 20:24
    @version:v1.0
'''
#当没有父亲目录是=时，可以先创建父亲目录
import os
import traceback


def f_copy(p_source,p_dest):
    v_source=os.path.abspath(p_source)
    v_dest=os.path.abspath(p_dest)
    if not os.path.exists(v_source):
        print('没找到原始文件')
        return None
    else:
        v_dest_father=os.path.dirname(v_dest)
        if not os.path.exists(v_dest_father):
            os.makedirs(v_dest_father)
            pass
        try:
            v_source_in=open(v_source,'br')
            v_dest_out=open(v_dest,'bw')
            v_result:bytes=b''
            v_lenth=1024
            v_result=v_source_in.read(v_lenth)
            while v_result:
                print(v_result)
                v_result = v_source_in.read(v_lenth)
                pass
        except:
            traceback.print_exc()
        finally:
            if v_source_in:
                v_source_in.close()
                pass
            if v_dest_out:
                v_dest_out.close()
                pass
            pass
        pass
    pass



